package com.jakewharton.disklrucache;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Environment;


import com.xijia.wuyouwallet.config.FusionCode;

import java.io.File;

/**
 * Created by Administrator on 2017/7/31 0031.
 */

public class DiskLruUtil {


    /**
     *
     * @param context
     * @return
     */
    public static String getCurrentAppVersion(Context context){
        String pName = FusionCode.PKG_NAME;
        try {
            PackageInfo pinfo = context.getPackageManager().getPackageInfo(pName,
                    PackageManager.GET_CONFIGURATIONS);
            String versionName = pinfo.versionName;
            return versionName;
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }

    }


    /**
     *
     * @param context
     * @return
     */
    public static int getCurrentAppVersionCode(Context context){
        String pName = FusionCode.PKG_NAME;
        try {
            PackageInfo pinfo = context.getPackageManager().getPackageInfo(pName,
                    PackageManager.GET_CONFIGURATIONS);
            int versionCode = pinfo.versionCode;
            return versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            return 0;
        }

    }


    /**
     *
     * @param context
     * @param uniqueName
     * @return
     */
    public static File getDiskCacheDir(Context context, String uniqueName) {
        String cachePath;
        if (Environment.MEDIA_MOUNTED.equals(Environment
                .getExternalStorageState())
                || !Environment.isExternalStorageRemovable()) {
            if (context.getExternalCacheDir() == null) {
                cachePath = context.getCacheDir().getPath();
            } else {
                cachePath = context.getExternalCacheDir().getPath();
            }

        } else {
            cachePath = context.getCacheDir().getPath();
        }
        return new File(cachePath + File.separator + uniqueName);
    }

}
